#ifndef BINARYINSTREAMHH
#define BINARYINSTREAMHH
#include "typedefs.hh"

namespace licada
{
    class IBinaryInStream
    {
    public:
	virtual ~IBinaryInStream(){}
	virtual void operator>>( uint8& val ) = 0;
	virtual void operator>>( TDataVector& data ) = 0;
    };

    class VectorBinaryInStream : public IBinaryInStream
    {
    protected:
	licada::TDataVector* data;
	licada::uint32 index;
	
    public:
	VectorBinaryInStream() : data(NULL), index(0) {}
	virtual void setup( TDataVector* _data ) { data = _data; index = 0; }
	virtual void operator>>( uint8& val ) { read( (licada::uint8*)&val, 1 ); }
	virtual void operator>>( TDataVector& data ) {
	    read( (licada::uint8*)&(*data.begin()), data.size() );
	}
    protected:
	virtual void read( licada::uint8* target, licada::uint32 len ) {
	    for( unsigned idx = 0; idx < len; ++idx, ++target )
		*target = data->at(index+idx);
	    index += len;
	}
    };
}

#endif
